<template>
  <div>
    <div class="customer-service">
      <a @click="customerHandler()">
        <i class="fas fa-headset"></i> 银 行 客 服
      </a>
    </div>

    <el-dialog :visible.sync="showDialog" append-to-body :custom-class="'el-dialog_unit'" width="70%">
      <div slot="title" class="dialog-title">
        <el-input placeholder="请输入搜索内容" prefix-icon="el-icon-search" v-model="searchVal" class="search-input">
        </el-input>
      </div>
      <div class="services-row">
        <div class="service-item" v-for="item in filteredData" :key="item.id" @click="toolClickHandler(item)">
          <div class="service-icon">
            <img :src="item.icon" alt="logo" v-if="item.icon && item.icon != ''">
            <i class="fa-solid fa-headset" v-else></i>
          </div>
          <span>{{ item.org_name }}</span>
        </div>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { MessageBox, Message } from 'element-ui';

export default {
  name: 'Customer',
  data() {
    return {
      showDialog: false,
      searchVal: '',
      customerServiceList: [
        {
          id: 1,
          org_name: '中国工商银行客服',
          cust_server_url: 'https://www.icbc.com.cn/',
          icon: ''
        },
        {
          id: 2,
          org_name: '中国建设银行客服',
          cust_server_url: 'https://www.ccb.com/',
          icon: ''
        },
        {
          id: 3,
          org_name: '中国农业银行客服',
          cust_server_url: 'https://www.abchina.com/',
          icon: ''
        },
        {
          id: 4,
          org_name: '中国银行客服',
          cust_server_url: 'https://www.boc.cn/',
          icon: ''
        },
        {
          id: 5,
          org_name: '交通银行客服',
          cust_server_url: 'https://www.bankcomm.com/',
          icon: ''
        },
        {
          id: 6,
          org_name: '招商银行客服',
          cust_server_url: 'https://www.cmbchina.com/',
          icon: ''
        }
      ]
    }
  },
  created() {
    // 这里可以调用API获取银行客服列表
    // this.getCustomerService();
  },
  computed: {
    filteredData() {
      if (!this.searchVal) {
        return this.customerServiceList;
      }
      return this.filterData(JSON.parse(JSON.stringify(this.customerServiceList)), this.searchVal.toLowerCase());
    }
  },
  methods: {
    filterData(data, keyword) {
      return data.filter(item => {
        const match = item.org_name.toLowerCase().includes(keyword);
        return match;
      });
    },
    
    /**
     * 获取银行客服列表（占位符实现）
     */
    getCustomerService() {
      // 这里应该调用实际的API
      // 目前使用静态数据
      console.log('获取银行客服列表');
    },
    
    customerHandler() {
      this.showDialog = true;
    },
    
    /**
     * 银行客服点击事件
     * @param item 
     */
    toolClickHandler(item) {
      if (item.cust_server_url) {
        MessageBox.confirm('确定要前往 ' + item.org_name + ' 吗？', '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'info'
        }).then(() => {
          window.open(item.cust_server_url, '_blank');
        })
      } else {
        Message.error('无效链接');
      }
    }
  }
};
</script>

<style lang="less" scoped>
.customer-service {
  margin-bottom: 20px;
}

.customer-service a {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 15px 20px;
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  color: white;
  text-decoration: none;
  border-radius: 12px;
  font-weight: 500;
  transition: all 0.3s ease;
  cursor: pointer;
  box-shadow: 0 4px 15px rgba(102, 126, 234, 0.3);
}

.customer-service a:hover {
  transform: translateY(-2px);
  box-shadow: 0 6px 20px rgba(102, 126, 234, 0.4);
}

.customer-service a i {
  font-size: 18px;
}

.dialog-title {
  display: flex;
  justify-content: center;
}

.search-input {
  width: 100%;
  max-width: 300px;
}

.services-row {
  display: flex;
  flex-direction: row;
  flex-wrap: wrap;
  justify-content: center;
  gap: 10px;
}

.service-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px;
  background: white;
  border: 1px solid #e6e6e6;
  border-radius: 8px;
  cursor: pointer;
  transition: all 0.3s ease;
  width: 30%;
  font-size: 16px;
}

.service-item:hover {
  background: #f8f9fa;
  border-color: #2196f3;
  transform: translateY(-1px);
  box-shadow: 0 2px 8px rgba(33, 150, 243, 0.1);
}

.service-icon {
  width: 30px;
  height: 30px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: #f0f0f0;
  border-radius: 6px;
  flex-shrink: 0;
}

.service-icon img {
  width: 24px;
  height: 24px;
  border-radius: 4px;
}

.service-icon i {
  color: rgba(21, 101, 192, 0.85);
  font-size: 16px;
}

.service-item span {
  flex: 1;
  font-size: 14px;
  color: #333;
  font-weight: 500;
}

/* 响应式设计 */
@media (max-width: 768px) {
  .service-item {
    width: 45%;
  }
  
  .customer-service a {
    padding: 12px 16px;
    font-size: 14px;
  }
}

@media (max-width: 480px) {
  .service-item {
    width: 100%;
  }
}
</style>
